package cn.maszy.action.systemsetting;

import java.util.List;
import net.sourceforge.stripes.action.SessionScope;
import org.springframework.beans.factory.annotation.Autowired;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.model.systemsetting.B_T_Ufp_Category;
import cn.maszy.model.systemsetting.B_T_Ufp_MaterialCategory;
import cn.maszy.service.systemsetting.B_T_Ufp_MaterialCategoryService;

@SessionScope
public class MaterialCategoryAction extends BaseAction<B_T_Ufp_MaterialCategory> {
	/**
	 * 版本控制信息
	 */
	private static final long serialVersionUID = 6179604301571294802L;
	private B_T_Ufp_MaterialCategory b_T_Ufp_MaterialCategory;
	@Autowired
	private B_T_Ufp_MaterialCategoryService b_T_Ufp_MaterialCategoryService;
	private String checkIds;
	private String flag;
	private String categoryStatus;
	//用于传递我的工程时 给具体部位增加数据时，传递uuid和那么给他的子类。
	private String positiontype;
	//是否可以修改价格
	private String isupdate;
	private List<B_T_Ufp_MaterialCategory> list_b_T_Ufp_MaterialCategory;
	/*******************STRUTS ACTION METHOD*************************/
	//删除
	public String materialCategoryDelete() throws Exception {
		int i=b_T_Ufp_MaterialCategoryService.delete(checkIds);
		if(i>0)
//		return ajaxForwardSuccess(getText("msg.operation.success"), "accountList","", "forward", "systemsetting/Category_buweiList");
			if("0".equals(flag))
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiList", "closeCurrent", "");
			}
			else if("1".equals(flag))
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiListH", "closeCurrent", "");
			}
			else if(b_T_Ufp_MaterialCategory.getCategoryStatus().equals("0"))
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiList", "", "");
			}
			else
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiListH", "", "");
			}
		
		else if(i==0)
		{
			return ajaxForwardError(getText("此类别下有数据无法删除"));
		}
			return ajaxForwardError(getText("msg.operation.failure"));
	}
	//修改新增
	public String materialCategoryUpdate() throws Exception {
		
			b_T_Ufp_MaterialCategory.setCategoryStatus(categoryStatus); 
			
		int i=b_T_Ufp_MaterialCategoryService.update(b_T_Ufp_MaterialCategory);
		if(i>0)
			//目前只有点击提交后关闭
			if(b_T_Ufp_MaterialCategory.getCategoryStatus().equals("0"))
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiList", "closeCurrent", "");
			}
			else
			{
				return ajaxForwardSuccess(getText("msg.operation.success"), "","materialbuweiListH", "closeCurrent", "");
			}
		
		//保存不关闭暂时没做
		//closeCurrent
		//return ajaxForwardSuccess(getText("msg.operation.success"), "categoryList","", "forward", "systemsetting/Category_categoryList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	//类别名称查找带回
	public String materialCallback() throws Exception {
		b_T_Ufp_MaterialCategory = new B_T_Ufp_MaterialCategory();
		b_T_Ufp_MaterialCategory.setCategoryStatus(categoryStatus);
		pager = new Pager<B_T_Ufp_MaterialCategory>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_MaterialCategoryService.selectList(b_T_Ufp_MaterialCategory,pager);
		return SUCCESS;
	}
	public String materialCategoryList() throws Exception {
		b_T_Ufp_MaterialCategory = new B_T_Ufp_MaterialCategory();
		b_T_Ufp_MaterialCategory.setCategoryStatus(categoryStatus);
		
//		pager = new Pager<B_T_Ufp_MaterialCategory>(pageNum, numPerPage,orderField,orderDirection);
//		pager= b_T_Ufp_MaterialCategoryService.selectList(b_T_Ufp_MaterialCategory,pager);
		list_b_T_Ufp_MaterialCategory=b_T_Ufp_MaterialCategoryService.select(b_T_Ufp_MaterialCategory);
		return SUCCESS;
	}
	public String materialCategoryRecycling() throws Exception {
		request.getSession().removeAttribute("Materialitem");
		b_T_Ufp_MaterialCategory = new B_T_Ufp_MaterialCategory();
		b_T_Ufp_MaterialCategory.setCategoryStatus(categoryStatus);
		//给pid设置0 的值，查询的时候不查pid为0的
		b_T_Ufp_MaterialCategory.setPid("0");
//		pager = new Pager<B_T_Ufp_MaterialCategory>(pageNum, numPerPage,orderField,orderDirection);
//		pager= b_T_Ufp_MaterialCategoryService.selectList(b_T_Ufp_MaterialCategory,pager);
		list_b_T_Ufp_MaterialCategory=b_T_Ufp_MaterialCategoryService.select(b_T_Ufp_MaterialCategory);
		return SUCCESS;
	}
	//局部刷新时使用
	public String materialbuweiList() throws Exception {
		b_T_Ufp_MaterialCategory = new B_T_Ufp_MaterialCategory();
		b_T_Ufp_MaterialCategory.setCategoryStatus(categoryStatus);
		
		list_b_T_Ufp_MaterialCategory=b_T_Ufp_MaterialCategoryService.select(b_T_Ufp_MaterialCategory);
//		pager = new Pager<B_T_Ufp_MaterialCategory>(pageNum, numPerPage,orderField,orderDirection);
//		pager= b_T_Ufp_MaterialCategoryService.selectList(b_T_Ufp_MaterialCategory,pager);
		return SUCCESS;
	}
	
	public String materialCategoryDetail() throws Exception {
		if(b_T_Ufp_MaterialCategory==null){
			b_T_Ufp_MaterialCategory=b_T_Ufp_MaterialCategoryService.selectOne("");
			b_T_Ufp_MaterialCategory=new B_T_Ufp_MaterialCategory();
			b_T_Ufp_MaterialCategory.setCategoryStatus(flag);
			
		}else{
			b_T_Ufp_MaterialCategory=b_T_Ufp_MaterialCategoryService.selectOne(b_T_Ufp_MaterialCategory.getUuid());
		}
		list_b_T_Ufp_MaterialCategory = b_T_Ufp_MaterialCategoryService.selectchange(b_T_Ufp_MaterialCategory);
		return SUCCESS;
	}
	
	
	/********************* class set/get ****************************/
	
	public B_T_Ufp_MaterialCategory getB_T_Ufp_MaterialCategory() {
		return b_T_Ufp_MaterialCategory;
	}

	public void setB_T_Ufp_MaterialCategory(B_T_Ufp_MaterialCategory b_T_Ufp_MaterialCategory) {
		this.b_T_Ufp_MaterialCategory = b_T_Ufp_MaterialCategory;
	}
	
	public String getCheckIds() {
		return checkIds;
	}

	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public String getCategoryStatus() {
		return categoryStatus;
	}
	public void setCategoryStatus(String categoryStatus) {
		this.categoryStatus = categoryStatus;
	}
	public List<B_T_Ufp_MaterialCategory> getList_b_T_Ufp_MaterialCategory() {
		return list_b_T_Ufp_MaterialCategory;
	}
	public void setList_b_T_Ufp_MaterialCategory(
			List<B_T_Ufp_MaterialCategory> list_b_T_Ufp_MaterialCategory) {
		this.list_b_T_Ufp_MaterialCategory = list_b_T_Ufp_MaterialCategory;
	}
	public String getPositiontype() {
		return positiontype;
	}
	public void setPositiontype(String positiontype) {
		this.positiontype = positiontype;
	}
	public String getIsupdate() {
		return isupdate;
	}
	public void setIsupdate(String isupdate) {
		this.isupdate = isupdate;
	}
}
